1. /* sdcbse.cpp by K.Tsuru */
  2. // function ID = 3554 DRADIX
  3. /***********************************************************************************************
  4. Basic file for computation of e=2.7181... with Xavier Gourdon's
  5. binary splitting method.
  6. CPU time = 23.5017(sec) 10000029(10 million digits) gcc 4.8.1 + CPU Core i7-3770 3.4GHz
  7. [reference]
  8. e.c in
  9. http://xavier.gourdon.free.fr/Constants/constants.html
  10. The implement is almost the same.
  11. Xavier Gourdon's binary splitting method is based on the original work of
  12. E.A.Karatsuba, "Fast evaluation of hypergeometric functions by FEE", CMFT'97.
  13. See "Binary splitting method" in http://numbers.computation.free.fr/Constants/constants.html .
  14. ************************************************************************************************/
  15. #ifndef SN_H
  16. #include "sn.h"
  17. #endif
  18. /********************
  19. In snum.h
  20. #define SLONG 2
  21. #define SDOUBLE 3
  22. #define SDEC_INT 4
  23. are defined.
  24. Speed test for 524,252 digits on Pentium 4 3GHz.
  25. version | CPU time (sec.)
  26. ---------------------
  27. SLONG | 6.2 ... fastest
  28. SDOUBLE | 9.3
  29. SDEC_INT| 9.65
  30. ********************/
  31. ////////////////////
  32. #define BSE_TYPE SLONG // for speed test change here
  33. ///////////////////
  34. #if BSE_TYPE==SLONG
  35. /// SLong version ///
  36. class BSExp1 : public BinarySplittingA1C<SLong> {
  37. public:
  38. BSExp1(long L, long prec) : BinarySplittingA1C<SLong>(L, prec) {}
  39. void setAC(long k, SLong& a, SLong& c) {
  40. a.SetSmall(1); c.SetLong(k + 1L);
  41. }
  42. SDouble getValue() {
  43. putTogether();
  44. return BinarySplittingA1C<SLong>::getValue() + 1.0;
  45. }
  46. };
  47. #elif BSE_TYPE==SDEC_INT
  48. /// SInteger version ///
  49. class BSExp1 : public BinarySplittingA1C<SInteger> {
  50. public:
  51. BSExp1(long L, long prec) : BinarySplittingA1C<SInteger>(L, prec) {}
  52. void setAC(long k, SInteger& a, SInteger& c) {
  53. a.SetSmall(1); c.SetLong(k + 1L);
  54. }
  55. SDouble getValue() {
  56. putTogether();
  57. SLong a , c;
  58. a = getA().ConvToDec();
  59. c = getC().ConvToDec();
  60. return SDouble(a) / SDouble(c) + 1.0;
  61. }
  62. };
  63. #else
  64. /// SDouble version ///
  65. class BSExp1 : public BinarySplittingA1C<SDouble> {
  66. public:
  67. BSExp1(long L, long prec) : BinarySplittingA1C<SDouble>(L, prec) {}
  68. void setAC(long k, SDouble& a, SDouble& c) {
  69. a.SetSmall(1);
  70. //c = k + 1L;
  71. c.SetInt(k + 1L);
  72. }
  73. SDouble getValue() {
  74. putTogether();
  75. return BinarySplittingA1C<SDouble>::getValue() + 1.0;
  76. }
  77. };
  78. #endif
  79. SDouble BSE() {
  80. SDouble temp;
  81. long prec = long(temp.EffFig() + temp.Hidden()) * DFIGURES;
  82. long L = upToExpSeries(prec, 0.0);
  83. #if BSE_TYPE==SDOUBLE
  84. BSExp1 e(L, 0); // does not need roundoff
  85. #else
  86. BSExp1 e(L, prec);
  87. #endif
  88. return e.getValue();
  89. }

sdcbse.cpp : last modifiled at 2017/03/17 11:10:45(2,708 bytes)
created at 2017/10/07 10:21:15
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).